import axios from 'axios';

// 设置baseURL
axios.defaults.baseURL = '/';

type LiveRoom = {
  roomid: number;
  uid: number;
  title: string;
  uname: string;
  online: number;
  user_cover: string;
  user_cover_flag: number;
  system_cover: string;
  cover: string;
  show_cover: string;
  link: string;
  face: string;
  parent_id: number;
  parent_name: string;
  area_id: number;
  area_name: string;
  area_v2_parent_id: number;
  area_v2_parent_name: string;
  area_v2_id: number;
  area_v2_name: string;
  session_id: string;
  group_id: number;
  show_callback: string;
  click_callback: string;
  web_pendent: string;
  pk_id: number;
  pendant_info: {
    [key: string]: {
      pendent_id: number;
      content: string;
      color: string;
      pic: string;
      position: number;
      type: string;
      name: string;
    };
  };
  verify: {
    role: number;
    desc: string;
    type: number;
  };
  head_box: {
    name: string;
    value: string;
    desc: string;
  };
  head_box_type: number;
  is_auto_play: number;
  flag: number;
  watched_show: {
    switch: boolean;
    num: number;
    text_small: string;
    text_large: string;
    icon: string;
    icon_location: number;
    icon_web: string;
  };
  is_nft: number;
  nft_dmark: string;
};

type Gift = {
  gift_id: number;
  num: number;
  gift_name: string;
  gift_pic: string;
};

type Lottery = {
  lot_id: number;
  sender_uid: number;
  sender_name: string;
  sender_face: string;
  join_requirement: number;
  danmu: string;
  awards: Gift[];
  start_time: number;
  end_time: number;
  last_time: number;
  remove_time: number;
  replace_time: number;
  current_time: number;
  lot_status: number;
  h5_url: string;
  user_status: number;
  lot_config_id: number;
  total_price: number;
  wait_num: number;
};
export type Room = {
  pk: null | unknown,
  guard: null | unknown,
  gift: null | unknown,
  storm: null | unknown,
  silver: null | unknown,
  activity_box: {
    ACTIVITY_ID: number,
    ACTIVITY_PIC: string
  } | null,
  danmu: null | unknown,
  anchor: {
    id: number,
    room_id: number,
    status: number,
    asset_icon: string,
    award_name: string,
    award_num: number,
    award_image: string,
    danmu: string,
    time: number,
    current_time: number,
    join_type: number,
    require_type: number,
    require_value: number,
    require_text: string,
    gift_id: number,
    gift_name: string,
    gift_num: number,
    gift_price: number,
    cur_gift_num: number,
    goaway_time: number,
    award_users: null | unknown,
    show_panel: number,
    url: string,
    lot_status: number,
    web_url: string,
    send_gift_ensure: number,
    goods_id: number,
    award_type: number,
    award_price_text: string,
    ruid: number,
    asset_icon_webp: string,
    danmu_type: number,
    danmu_new: {
      danmu: string,
      danmu_view: string,
      reject: boolean
    }[]
  } | null,
  red_pocket: null | unknown,
  popularity_red_pocket: null | Lottery[],
  activity_box_info: null | unknown,
  magic_wish_info: {
    icon: string,
    is_show: boolean,
    title: string,
    type: number,
  }
}

export type RoomDataItem = {
  roomid: number;
  data: Room;
  room: LiveRoom;
}

// getRedPocketRoomList 接口对应的前端函数
export const getRedPocketRoomList = async () => {
  try {
    const res = await axios.get('/getRedPocketRoomList');
    return res.data as RoomDataItem[];
  } catch (error) {
    console.error(error);
    throw error;
  }
};

// getAnchorPocketRoomList 接口对应的前端函数
export const getAnchorPocketRoomList = async () => {
  try {
    const res = await axios.get('/getAnchorPocketRoomList');
    return res.data as RoomDataItem[];
  } catch (error) {
    console.error(error);
    throw error;
  }
};

// start 接口对应的前端函数
export const startInterval = async () => {
  try {
    const res = await axios.get('/start');
    return res.data;
  } catch (error) {
    console.error(error);
    throw error;
  }
};

// end 接口对应的前端函数
export const endInterval = async () => {
  try {
    const res = await axios.get('/end');
    return res.data;
  } catch (error) {
    console.error(error);
    throw error;
  }
};
